/***************************************************************************//**
 * @file CGI/DataTypeSkyDome.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2014 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef DATA_TYPE_SKY_DOME_H
#define DATA_TYPE_SKY_DOME_H

////////////////////////////////////////////////////////////////////////////////

#include <osg/PositionAttitudeTransform>

#ifdef MSCSIM_OSGEPHEMERIS
#   include <osgEphemeris/EphemerisModel.h>
#   include <Utils.h>
#endif

#include "DataType.h"

////////////////////////////////////////////////////////////////////////////////

class DataTypeSkyDome : public DataType
{
public:

    /** */
    DataTypeSkyDome( osg::Node * node );

    /** */
    virtual void update();

    /** */
    virtual inline double getSunElevation() const
    {
#       ifndef MSCSIM_OSGEPHEMERIS
        return m_elevation;
#       else
        return m_ephemerisModel->getEphemerisData()->data[osgEphemeris::CelestialBodyNames::Sun].alt;
#       endif
    }

    /** */
    virtual inline void setPosition( osg::Vec3 position )
    {
        m_position = position;
    }

    /** */
    virtual inline void setScale( double scale )
    {
        m_sizeCoef = osg::Vec3( scale, scale, scale );
    }

    /** */
    virtual inline void setAttitude( osg::Quat attitude )
    {
        m_attitude = attitude;
    }

#   ifndef MSCSIM_OSGEPHEMERIS
    /** */
    virtual inline void setElevation( double elevation )
    {
        m_elevation = elevation;
    }
#   else
    /** */
    virtual inline void setDateTime( Utils::DateTime dateTime )
    {
        m_dateTime = dateTime;
    }

    /**
     * @param lat [deg]
     * @param lon [deg]
     * @param alt [m]
     */
    virtual inline void setLatLonAlt( double lat, double lon, double alt )
    {
        m_lat = lat;
        m_lon = lon;
        m_alt = alt;
    }
#   endif

protected:

    osg::Vec3 m_position;
    osg::Vec3 m_sizeCoef;
    osg::Quat m_attitude;

#   ifndef MSCSIM_OSGEPHEMERIS
    double m_elevation;
#   else
    Utils::DateTime m_dateTime;
    Utils::DateTime m_dateTime_prev;

    double m_lat;   ///< [deg]
    double m_lon;   ///< [deg]
    double m_alt;   ///< [m]
#   endif

    osg::ref_ptr<osg::PositionAttitudeTransform> m_skyDomePosition;
    osg::ref_ptr<osg::PositionAttitudeTransform> m_skyDomeSizeCoef;
    osg::ref_ptr<osg::PositionAttitudeTransform> m_skyDomeAttitude;

#   ifndef MSCSIM_OSGEPHEMERIS
    osg::ref_ptr<osg::Geode> m_skyDomeGeode;

    int m_textureId;
    int m_textureId_prev;

    bool m_textureDay;
    bool m_textureNight;

    std::vector<std::string> m_textures;
#   else
    osg::ref_ptr<osgEphemeris::EphemerisModel> m_ephemerisModel;
#   endif

    /** */
    virtual void updatePosition();

    /** */
    virtual void updateScale();

    /** */
    virtual void updateAttitude();

#   ifndef MSCSIM_OSGEPHEMERIS
    /** */
    virtual void updateTexture();
#   else
    /** */
    virtual void updateEphemeris();
#   endif
};

////////////////////////////////////////////////////////////////////////////////

#endif // DATA_TYPE_SKY_DOME_H
